//package cn.com.w.secutity.Security.filter;
//
//import org.springframework.stereotype.Component;
//
//import javax.servlet.*;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//
///**
// * @author w
// * @Description:
// * @DateTime: 2025 05 14 12:44
// **/
//@Component
//public class CorsFilter implements Filter {
//
//    @Override
//    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
//        HttpServletRequest request = (HttpServletRequest) req;
//        HttpServletResponse response = (HttpServletResponse) res;
//
//        // 设置允许跨域的域名，* 表示允许所有域名进行跨域调用
//        response.setHeader("Access-Control-Allow-Origin", "*");
//        // 设置允许的请求方法
//        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
//        // 设置允许的请求头
//        response.setHeader("Access-Control-Allow-Headers", "Authorization, Content-Type");
//        // 设置允许携带凭证，例如 cookie
//        response.setHeader("Access-Control-Allow-Credentials", "true");
//
//        // 对于 OPTIONS 请求直接返回 200 状态码
//        if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
//            response.setStatus(HttpServletResponse.SC_OK);
//        } else {
//            chain.doFilter(req, res);
//        }
//    }
//
//    @Override
//    public void init(FilterConfig filterConfig) {
//    }
//
//    @Override
//    public void destroy() {
//    }
//}